package com.cse.htmlparser;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Catalog implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HashMap<String,String> map ;
	
	public Catalog(){
		map = new HashMap<String,String>();
	}
	
	public void addItem(String title,String url){
		map.put(title, url);
	}
	
	public String getItem(String title){
		return map.get(title);
	}
	
	public void rmItem(String title){
		map.remove(title);
	}
	
	public void clear(){
		map.clear();
	}
	
	public void writeFile(String path){
		try{
			ObjectOutputStream out = new ObjectOutputStream( 
					new BufferedOutputStream(new FileOutputStream(path))); 
			out.writeObject(this.map); 
			out.close(); 
			} catch (Exception e) { 
				System.out.println(e); 
		}
	}
	
	@SuppressWarnings("unchecked")
	public Map<String,String> getMap(String path){
		File inFile = new File(path); 
		Object o = null; 
		
		try { 
		ObjectInputStream in = new ObjectInputStream( 
		new BufferedInputStream(new FileInputStream(inFile))); 
		o = in.readObject(); 
		in.close(); 
		} catch (Exception e) { 
			System.out.println(e); 
		} 
		return (Map<String, String>) o; 
		} 
	}

	
	

